<?php

namespace App\Containers\AppSection\BankDetail\Tasks;

use App\Containers\AppSection\BankDetail\Data\Repositories\BankDetailRepository;
use App\Containers\AppSection\BankDetail\Models\BankDetail;
use App\Ship\Exceptions\UpdateResourceFailedException;
use App\Ship\Parents\Tasks\Task;

class UpdateBankDetailTask extends Task
{
    protected BankDetailRepository $repository;

    public function __construct(BankDetailRepository $repository)
    {
        $this->repository = $repository;
    }

    public function run(int $id, array $data): BankDetail
    {
        try {
            return $this->repository->update($data, $id);
        } catch (Exception $exception) {
            throw new UpdateResourceFailedException();
        }
    }
}
